package client.impl;

import java.rmi.RemoteException;

import org.omg.CORBA.ORB;

import client.ParticipantUser;
import client.RemoteParticipant;
import data.DataObject;
import embeded.EmbededObject;
import embeded.Participant;

public class RemoteParticipantImpl implements RemoteParticipant {
	private Participant participant;
	private ParticipantUser user = null;
	public ORB orb;
	private EmbededObject embeded;
	
	public RemoteParticipantImpl(Participant participent, ORB orb, EmbededObject embeded) {
		this.participant = participent;
		try {
			this.participant.setRemote(this);
		} catch (RemoteException e) {e.printStackTrace();}
		this.orb = orb;
		this.embeded = embeded;
	}
	
	public void setParticipantUser(ParticipantUser user) throws RemoteException{
		this.user = user;
	}
	
	public void setData(Object data) throws RemoteException{
		try {
			DataObject dataaa = new DataObject(orb.create_any());
			dataaa.setString((String)data);
			participant.setData(dataaa);
			embeded.showFrame();
			embeded.refreshParticipants(participant.getName());
		} catch (RemoteException e) {e.printStackTrace();}
	}

	public Object getData() throws RemoteException{
		try {
			return participant.getData().getString();
		} catch (RemoteException e) {e.printStackTrace();}
		return null;
	}

	public void endUsing(String topicFullName) throws RemoteException{
		embeded.removeParticipant(topicFullName);
	}
	
	public void refreshParticipantUser() throws RemoteException{
		user.refresh();
	}
}
